### Main survey experimental analysis (presented in paper and SI)
### Replication Package associated with Perspectives on Politics article
### "How Police Behavior Shapes Perceptions of Protests: Evidence from Black Lives Matter"
### Jasmine English, Ariel White, Laurel Eckhouse

## Load packages and data ----

# Packages
library(dplyr)
library(data.table)
library(xtable)
library(stats)
library(Matching)
library(ebal)
library(ggplot2)
library(stargazer)
library(gridExtra)

# Load data
svy <- read.csv("police_0522_cleaned.csv", header=T, stringsAsFactors=F)

## Data cleaning and creating dummies ----

svy$female <- ifelse(svy$Q2=="Woman", 1, 0)
svy$race <- svy$Q3
svy$age <- as.factor(svy$Q4)
svy$party <- svy$Q5
svy$white <- ifelse(svy$Q3=="White, not Hispanic", 1, 0)
svy$black <- ifelse(svy$Q3=="African-American or Black", 1, 0)
svy$hisp <- ifelse(svy$Q3=="Hispanic or Latino", 1, 0)
svy$asian <- ifelse(svy$Q3=="Asian American or Pacific Islander", 1, 0)

svy$race3 <- ifelse(svy$Q3=="White, not Hispanic", "White", svy$Q3)
svy$race3 <- ifelse(svy$race3=="African-American or Black", "Black", svy$race3)
svy$race3 <- ifelse(!svy$race3=="White"&!svy$race3=="Black", "Other", svy$race3)

svy$dem <- ifelse(svy$Q5=="Democrat", 1, 0)
svy$rep <- ifelse(svy$Q5=="Republican", 1, 0)
svy$ind <- ifelse(svy$Q5=="Independent", 1, 0)

svy$under18 <- ifelse(svy$age=="Under 18", 1, 0)
svy$age18to29 <- ifelse(svy$age=="Age 18 to 29", 1, 0)
svy$age30to39 <- ifelse(svy$age=="Age 30 to 39", 1, 0)
svy$age40to49 <- ifelse(svy$age=="Age 40 to 49", 1, 0)
svy$age50to59 <- ifelse(svy$age=="Age 50 to 59", 1, 0)
svy$age60plus <- ifelse(svy$age=="Age 60 or above", 1, 0)


## Set up treatment indicator
svy$MilitarizedPolice<- ifelse(is.na(svy$Q9_Page.Submit), 0, 1)

## Event in question was violent
svy$EventViolent <- recode(svy$o_violentevent, "Strongly disagree"=1,"Somewhat disagree"=2,"Neither agree nor disagree"=3,"Somewhat agree"=4,"Strongly agree"=5)

## Protesters had violent intentions
svy$IntentionsViolent <- recode(svy$o_violentintentions, "Strongly disagree"=1,"Somewhat disagree"=2,"Neither agree nor disagree"=3,"Somewhat agree"=4,"Strongly agree"=5)

## Protesters were out to cause trouble
svy$CauseTrouble <- recode(svy$o_trouble, "Strongly disagree"=1,"Somewhat disagree"=2,"Neither agree nor disagree"=3,"Somewhat agree"=4,"Strongly agree"=5)
svy$CauseCauseTrouble_Dummy <- ifelse(svy$o_trouble=="Strongly agree" | svy$o_trouble=="Somewhat agree", 1, 0)
 
## I would consider getting involved with group
svy$GetInvolved <- recode(svy$o_involved, "Strongly disagree"=1,"Somewhat disagree"=2,"Neither agree nor disagree"=3,"Somewhat agree"=4,"Strongly agree"=5)

## Go to protest like this one
svy$GoProtest <- as.numeric(svy$o_actions_1)

## Post on social media
svy$SocialMedia <- as.numeric(svy$o_actions_2)

## Support these protesters
svy$SupportProtest <- recode(svy$o_support, "Strongly disagree"=1,"Somewhat disagree"=2,"Neither agree nor disagree"=3,"Somewhat agree"=4,"Strongly agree"=5)

## Figure A2 : Effects of Militarized Police on Index Variables (Violence Perceptions and Support for BLM Protesters) ----

svy$PerceptionViolent <- (svy$EventViolent + svy$IntentionsViolent + svy$CauseTrouble) / 3
PerceptionViolent_T <- t.test(svy$PerceptionViolent ~ svy$MilitarizedPolice)

svy$SupportBLM <- (svy$GetInvolved + svy$SupportProtest + svy$GoProtest/20 + svy$SocialMedia/20) / 4
SupportBLM_T <- t.test(svy$SupportBLM ~ svy$MilitarizedPolice) 

## Store effects for perception index
p_index_effects <- cbind(PerceptionViolent_T$estimate[2]-PerceptionViolent_T$estimate[1], -1*PerceptionViolent_T$conf.int[1], -1*PerceptionViolent_T$conf.int[2])
p_index_effects <- as.data.frame(p_index_effects)
colnames(p_index_effects) <- c("effects","CIlower", "CIupper")
rownames(p_index_effects) <- c("perception index")

## Store effects for support index
s_index_effects <- cbind(SupportBLM_T$estimate[2]-SupportBLM_T$estimate[1],-1*SupportBLM_T$conf.int[1],-1*SupportBLM_T$conf.int[2] )
s_index_effects <- as.data.frame(s_index_effects)
colnames(s_index_effects) <- c("effects","CIlower", "CIupper")
rownames(s_index_effects) <- c("support index")

index_effects <- as.data.frame(rbind(p_index_effects, s_index_effects))

# Line plot with error bars
pdf("pindexplot.pdf", width=4.5, height=3.5)
plot <- ggplot(data = index_effects, aes(y=c(.5,1.5), x=effects)) + 
  geom_vline(xintercept=0, linetype=2) +
  geom_point(size=2) +
  geom_pointrange(aes(xmin=CIlower, xmax=CIupper)) + theme_bw() +
  xlab("\n Treatment Effect") + ylab("") +
  theme(axis.title.y=element_blank(), text = element_text(size=12)) +
  scale_y_continuous(breaks=c(.5,1.5), labels=c("Perception Index  \n  (Control Mean = 1.75)", "Support Index  \n  (Control Mean = 2.76)"))
print(plot)
dev.off()

## Figure 5: Effects of Heavy Police Presence on Violence Perception ----

EventViolent_T <- t.test(svy$EventViolent ~ svy$MilitarizedPolice)
IntentionsViolent_T <- t.test(svy$IntentionsViolent ~ svy$MilitarizedPolice)
CauseTrouble_T <- t.test(svy$CauseTrouble ~ svy$MilitarizedPolice)

perception_diffs <- c(EventViolent_T$estimate[2]-EventViolent_T$estimate[1], IntentionsViolent_T$estimate[2]-IntentionsViolent_T$estimate[1], CauseTrouble_T$estimate[2]-CauseTrouble_T$estimate[1]) 
perception_labels <- c("The event in question was violent", "The protesters had violent intentions", "These protesters were out to cause trouble")

perception_CIlower <- c(EventViolent_T$conf.int[1], IntentionsViolent_T$conf.int[1], CauseTrouble_T$conf.int[1])*-1
perception_CIupper <- c(EventViolent_T$conf.int[2], IntentionsViolent_T$conf.int[2], CauseTrouble_T$conf.int[2])*-1
perception_effects <- cbind(perception_diffs, perception_CIlower,perception_CIupper)
perception_effects <- as.data.frame(perception_effects)
colnames(perception_effects) <- c("effects", "CIlower", "CIupper")
rownames(perception_effects) <- perception_labels

pdf("perceptionplot.pdf", width=6.5, height=4)
plot <- ggplot(data = perception_effects, aes(y=c(1,1.5,2), x=effects)) + 
  geom_vline(xintercept=0, linetype=2) +
  geom_point(size=2) +
  geom_pointrange(aes(xmin=CIlower, xmax=CIupper)) + theme_bw()+
  xlab("\n Treatment Effect (Treated - Control, on 5-point Likert Scale)") + ylab("") +
  theme(axis.title.y=element_blank(), text = element_text(size=12)) +
  scale_y_continuous(breaks=c(1,1.5,2), labels=c("Event Violent  \n  (Control Mean = 1.83)", 
                                                 "Intentions Violent\n  (Control Mean = 1.63)",
                                                 "Cause Trouble\n  (Control Mean = 1.79)"))
print(plot)
dev.off()

## Figure 6 : Effects of Police Presence on Support for BLM Protesters ----

SupportProtest_T <- t.test(svy$SupportProtest ~ svy$MilitarizedPolice) 
GetInvolved_T <- t.test(svy$GetInvolved ~ svy$MilitarizedPolice) 
GoProtest_T <- t.test(svy$GoProtest ~ svy$MilitarizedPolice)
SocialMedia_T <- t.test(svy$SocialMedia ~ svy$MilitarizedPolice)

support_diffs <- c(SupportProtest_T$estimate[2]-SupportProtest_T$estimate[1], GetInvolved_T$estimate[2]-GetInvolved_T$estimate[1], 
                   GoProtest_T$estimate[2]-GoProtest_T$estimate[1], SocialMedia_T$estimate[2]-SocialMedia_T$estimate[1])

support_CIlower <- c(SupportProtest_T$conf.int[1], GetInvolved_T$conf.int[1], GoProtest_T$conf.int[1], SocialMedia_T$conf.int[1])*-1 #swap sign because t.test set up control-treat
support_CIupper <- c(SupportProtest_T$conf.int[2], GetInvolved_T$conf.int[2], GoProtest_T$conf.int[2], SocialMedia_T$conf.int[2])*-1

support_labels <- c("I support these protestors", "I would consider getting involved with a group who supported causes similar to those of the protesters", 
                    "How likely would you be to take the following actions? Go to a protest like this one", 
                    "How likely would you be to take the following actions? Post something positive about a protest like this on social media")

support_effects <- cbind(support_diffs, support_CIlower, support_CIupper)
support_effects <- as.data.frame(support_effects)
colnames(support_effects) <- c("effects2", "CIlower", "CIupper")
rownames(support_effects) <- support_labels

plot1 <- ggplot(data = support_effects[1:2,], aes(y=c(1,1.5), x=effects2)) + 
  geom_vline(xintercept=0, linetype=2) +
  geom_point(size=2) +
  geom_pointrange(aes(xmin=CIlower, xmax=CIupper)) + theme_bw()+
  xlab("\n Treatment Effect") + ylab("") +
  theme(axis.title.y=element_blank(), text = element_text(size=12)) +
  scale_y_continuous(breaks=c(1,1.5), limits=c(.75,1.75), labels=c("Support  \n  (Control Mean = 3.84)",
                                                                   "Get Involved \n  (Control Mean = 3.16)"))

plot2 <- ggplot(data = support_effects[3:4,], aes(y=c(1,1.5), x=effects2)) + 
  geom_vline(xintercept=0, linetype=2) +
  geom_point(size=2) +
  geom_pointrange(aes(xmin=CIlower, xmax=CIupper)) + theme_bw()+
  xlab("\n Treatment Effect") + ylab("") +
  theme(axis.title.y=element_blank(), text = element_text(size=12)) +
  scale_y_continuous(breaks=c(1,1.5), limits=c(.75,1.75), labels=c("Go Protest \n  (Control Mean = 36.93)",
                                                                   "Social Media \n  (Control Mean = 43.92)"))

pdf("supportplot_paneled.pdf", width=8, height=3.5)
grid.arrange(plot1, plot2, nrow = 1)
dev.off()

## Table A5 : Covariate Means, April 2022 Prolific Sample ----

## Subset by gender
svy_female <- subset(svy, svy$female==1)
svy_male <- subset(svy, svy$female==0)

## Subset by race
svy_asian <- subset(svy, svy$race=="Asian American or Pacific Islander")
svy_hisp <- subset(svy, svy$race=="Hispanic or Latino")
svy_black <- subset(svy, svy$race=="African-American or Black")
svy_white <- subset(svy, svy$race=="White, not Hispanic")
svy_nonblack <- subset(svy, !svy$race=="African-American or Black")

## Subset by party
svy_dem <- subset(svy, svy$party=="Democrat")
svy_rep <- subset(svy, svy$party=="Republican")
svy_ind <- subset(svy, svy$party=="Independent")

## Subset by age
svy_under18 <- subset(svy, svy$age=="Under 18")
svy_18to29 <- subset(svy, svy$age=="Age 18 to 29")
svy_30to39 <- subset(svy, svy$age=="Age 30 to 39")
svy_40to49 <- subset(svy, svy$age=="Age 40 to 49")
svy_50to59 <- subset(svy, svy$age=="Age 50 to 59")
svy_60plus <- subset(svy, svy$age=="Age 60 or above")

# ## Store percentages
pct_fem <- (nrow(svy_female)/nrow(svy)) * 100
pct_asian <- (nrow(svy_asian)/nrow(svy)) * 100
pct_hisp <- (nrow(svy_hisp)/nrow(svy)) * 100
pct_black <- (nrow(svy_black)/nrow(svy)) * 100
pct_white <- (nrow(svy_white)/nrow(svy)) * 100
pct_dem  <- (nrow(svy_dem)/nrow(svy)) * 100
pct_rep  <- (nrow(svy_rep)/nrow(svy)) * 100
pct_ind  <- (nrow(svy_ind)/nrow(svy)) * 100
pct_under18 <- (nrow(svy_under18)/nrow(svy)) * 100
pct_18to29 <- (nrow(svy_18to29)/nrow(svy)) * 100
pct_30to39 <- (nrow(svy_30to39)/nrow(svy)) * 100
pct_40to49 <- (nrow(svy_40to49)/nrow(svy)) * 100
pct_50to59 <- (nrow(svy_50to59)/nrow(svy)) * 100
pct_60plus <- (nrow(svy_60plus)/nrow(svy)) * 100

desc_table <- rbind(pct_fem, pct_white,  pct_black, pct_asian,  pct_hisp, pct_dem,
                    pct_rep, pct_ind, pct_under18, pct_18to29, pct_30to39, pct_40to49,
                    pct_50to59, pct_60plus)
colnames(desc_table) <- c("Percent")
rownames(desc_table) <- c("Female", "White","Black","Asian","Hispanic","Democrat",
                          "Republican","Independent","Under 18", "18 to 29", "30 to 39",
                          "40 to 49", "50 to 59", "60 or above")
desc_table <- round(desc_table, 2)

stargazer(desc_table, header=FALSE, digits=2,
          title="Descriptive Statistics",
          type='latex', dep.var.labels.include = FALSE,
          model.names = FALSE, model.numbers = FALSE,
          style="apsr")

groupmeans <- svy %>% summarise_at(vars(female, asian, black, hisp, white, dem, rep, ind, under18,age18to29,age30to39, age40to49,age50to59, age60plus), mean)
groupbytreat <- svy %>% group_by(MilitarizedPolice) %>% summarise_at(vars(female, asian, black, hisp, white, dem, rep, ind, under18,age18to29,age30to39, age40to49,age50to59, age60plus), mean)
armtab <- cbind(t(groupmeans),t(groupbytreat[,2:15]))
colnames(armtab) <- c("All","Control","Militarized-Police Treatment")
rownames(armtab)<- c("Female", "Asian", "Black", "Hispanic", "White", "Democrat", "Republican", "Independent", "Under 18", "18-29", "30-39", "40-49", "50-59", "60+")

print(xtable(armtab, digits=c(0,3,3,3), caption="Covariate Means, April 2022 Prolific Sample", label="svybalance"), file="policingsvyexp_groupmeans.tex")

## Table A6: Effect of Heavy Police Presence on Violence Perception: Regressions ----
event_mod_1 <- lm(EventViolent ~ MilitarizedPolice, data=svy); summary(event_mod_1)
intention_mod_1 <- lm(IntentionsViolent ~ MilitarizedPolice, data=svy); summary(intention_mod_1)
trouble_mod_1 <- lm(CauseTrouble ~ MilitarizedPolice, data=svy); summary(trouble_mod_1)
stargazer(event_mod_1, intention_mod_1, trouble_mod_1, header=FALSE, 
          title="Effect of Heavy Police Presence on Violence Perception: Regressions", 
          type='latex', dep.var.labels.include = FALSE,
          model.names = FALSE,model.numbers = FALSE,
          column.labels   = c("Event Violent", "Intentions Violent","Cause Trouble"),
          column.separate = c(1,1,1), omit.stat = c("rsq", "f", "ser", "adj.rsq"),
          covariate.labels=c("Heavy Police Presence"),label="PerceptionRegression",
          star.cutoffs = c(0.05), notes="$^{*}$p$<$0.05", notes.append=FALSE,
          out="perception_table.tex")


## Table A7: Effect of Heavy Police Presence on BLM Support: Regressions ----
involved_mod_1 <- lm(GetInvolved ~ MilitarizedPolice, data=svy); summary(involved_mod_1)
actions_1_mod_1 <- lm(GoProtest ~ MilitarizedPolice, data=svy); summary(actions_1_mod_1)
actions_2_mod_1 <- lm(SocialMedia ~ MilitarizedPolice, data=svy); summary(actions_2_mod_1)
support_mod_1 <- lm(SupportProtest ~ MilitarizedPolice, data=svy); summary(support_mod_1)

stargazer(involved_mod_1, actions_1_mod_1, actions_2_mod_1, support_mod_1, header=FALSE, 
          title="Effect of Heavy Police Presence on BLM Support: Regressions", 
          type='latex', dep.var.labels.include = FALSE,
          model.names = FALSE, model.numbers = FALSE,
          column.labels   = c("Get Involved", "Go Protest","Social Media", "Support"),
          column.separate = c(1,1,1), omit.stat = c("rsq", "f", "ser", "adj.rsq"),
          column.sep.width = "-4pt",label="SupportRegression",
          covariate.labels=c("Heavy Police Presence"),
          star.cutoffs = c(0.05), notes="$^{*}$p$<$0.05", notes.append=FALSE,
          out="support_table.tex")

## Figure 7 : Racial Heterogeneity in Effects on Perceptions of Violence ----

#Plot that displays treatment effects by race
tstore <- function(groupname, outcome){
   subset <- svy[svy$race3==groupname,]
   test <- t.test(subset[,outcome] ~ subset$MilitarizedPolice) 
   return(c(test$estimate[2]-test$estimate[1], test$conf.int[1]*-1, test$conf.int[2]*-1, outcome, groupname))
}

racegroups <- c("White", "Black", "Other")

perceptionbyrace <- rbind(as.data.frame(t(sapply(racegroups, tstore,"CauseTrouble"))),as.data.frame(t(sapply(racegroups, tstore,"IntentionsViolent"))), as.data.frame(t(sapply(racegroups, tstore,"EventViolent"))))
colnames(perceptionbyrace) <- c("effects", "CIlower", "CIupper", "var", "group")

perceptionbyrace$effects <- as.numeric(perceptionbyrace$effects)
perceptionbyrace$CIlower <- as.numeric(perceptionbyrace$CIlower)
perceptionbyrace$CIupper <- as.numeric(perceptionbyrace$CIupper)

pdf("perceptionplot_byrace.pdf", width=6.5, height=4)

plot <- perceptionbyrace %>%
  ggplot(aes(x = var, y = effects,  shape=group)) +
  geom_hline(yintercept = 0, linetype = 2) +
  geom_point(position = position_dodge2(width = 1/4), size=3) +
  geom_errorbar(aes(ymin = CIlower, ymax = CIupper, width=0.001), position=position_dodge(width=1/4)) +
  theme_bw()+
  ylab("Treatment Effect") + ggtitle("Treatment Effect Heterogeneity by Race")+
  theme(plot.title = element_text(hjust = 0.5),axis.title.y=element_blank(), text = element_text(size=14)) +
  coord_flip()+  labs( shape = "Group")

print(plot)
dev.off()


# Figure 8 : Racial Heterogeneity in Effects on Protest Support ----

behaviorbyrace <- rbind(as.data.frame(t(sapply(racegroups, tstore,"SocialMedia"))),
                        as.data.frame(t(sapply(racegroups, tstore,"GoProtest"))),
                        as.data.frame(t(sapply(racegroups, tstore,"GetInvolved"))),
                        as.data.frame(t(sapply(racegroups, tstore,"SupportProtest"))))

colnames(behaviorbyrace) <- c("effects", "CIlower", "CIupper", "var", "group")
behaviorbyrace$effects <- as.numeric(behaviorbyrace$effects)
behaviorbyrace$CIlower <- as.numeric(behaviorbyrace$CIlower)
behaviorbyrace$CIupper <- as.numeric(behaviorbyrace$CIupper)

plot <- behaviorbyrace %>%
  ggplot(aes(x = var, y = effects,  shape=group)) +
  geom_hline(yintercept = 0, linetype = 2) + 
  geom_point(position = position_dodge2(width = 1/4), size=3) + 
  geom_errorbar(aes(ymin = CIlower, ymax = CIupper, width=0.001), position=position_dodge(width=1/4)) + 
  theme_bw()+
  ylab("Treatment Effect") + ggtitle("Treatment Effect Heterogeneity by Race")+
  theme(plot.title = element_text(hjust = 0.5),axis.title.y=element_blank(), text = element_text(size=14)) + 
  coord_flip()+  labs( shape = "Group") 

plot2 <- behaviorbyrace[1:6,] %>%
  ggplot(aes(x = var, y = effects,  shape=group)) +
  geom_hline(yintercept = 0, linetype = 2) +
  geom_point(position = position_dodge2(width = 1/4), size=3) +
  geom_errorbar(aes(ymin = CIlower, ymax = CIupper, width=0.001), position=position_dodge(width=1/4)) +
  theme_bw()+
  ylab("Treatment Effect") +
  theme(plot.title = element_text(hjust = 0.5),axis.title.y=element_blank(), text = element_text(size=14)) +
  coord_flip()+  labs( shape = "Group")

plot1 <- behaviorbyrace[7:12,] %>%
  ggplot(aes(x = var, y = effects,  shape=group)) +
  geom_hline(yintercept = 0, linetype = 2) +
  geom_point(position = position_dodge2(width = 1/4), size=3) +
  geom_errorbar(aes(ymin = CIlower, ymax = CIupper, width=0.001), position=position_dodge(width=1/4)) +
  theme_bw()+
  ylab("Treatment Effect") +
  theme(plot.title = element_text(hjust = 0.5),axis.title.y=element_blank(), text = element_text(size=14)) +
  coord_flip()+  labs( shape = "Group")

pdf("behaviorplot_byrace_paneled.pdf", width=8, height=3.5)
grid.arrange(plot1, plot2, nrow = 1)
dev.off()

## Table A8 : Effect of Heavy Police Presence on Violence Perceptions by Race: Regressions ----

EVb <- lm(EventViolent ~ MilitarizedPolice, data=svy[svy$race3=="Black",])
EVw <- lm(EventViolent ~ MilitarizedPolice, data=svy[svy$race3=="White",])
EVo <- lm(EventViolent ~ MilitarizedPolice, data=svy[svy$race3=="Other",])

IVb <- lm(IntentionsViolent ~ MilitarizedPolice, data=svy[svy$race3=="Black",])
IVw <- lm(IntentionsViolent ~ MilitarizedPolice, data=svy[svy$race3=="White",])
IVo <- lm(IntentionsViolent ~ MilitarizedPolice, data=svy[svy$race3=="Other",])

CTb <- lm(CauseTrouble ~ MilitarizedPolice, data=svy[svy$race3=="Black",])
CTw <- lm(CauseTrouble ~ MilitarizedPolice, data=svy[svy$race3=="White",])
CTo <- lm(CauseTrouble ~ MilitarizedPolice, data=svy[svy$race3=="Other",])

stargazer(EVb, EVw, EVo, IVb, IVw, IVo, CTb, CTw, CTo,
          title="Effect of Heavy Police Presence on Violence Perceptions by Race: Regressions", 
          float.env="sidewaystable",
          type='latex',
          dep.var.caption = "Dependent Variable:",
          column.labels = rep(c("Black","White","Other"),3),
          omit.stat = c("rsq", "f", "ser", "adj.rsq"),
          covariate.labels=c("Heavy Police Presence"),
          label="PerceptionbyRaceRegression",
          style="apsr", 
          star.cutoffs = c(0.05), notes="$^{*}$p$<$0.05", notes.append=FALSE,
          out="perceptions_byrace_table.tex")

## Table A9 : Effect of Heavy Police Presence on Protester Support by Race: Regressions ----

SPb <- lm(SupportProtest ~ MilitarizedPolice, data=svy[svy$race3=="Black",])
SPw <- lm(SupportProtest ~ MilitarizedPolice, data=svy[svy$race3=="White",])
SPo <- lm(SupportProtest ~ MilitarizedPolice, data=svy[svy$race3=="Other",])

GIb <- lm(GetInvolved ~ MilitarizedPolice, data=svy[svy$race3=="Black",])
GIw <- lm(GetInvolved ~ MilitarizedPolice, data=svy[svy$race3=="White",])
GIo <- lm(GetInvolved ~ MilitarizedPolice, data=svy[svy$race3=="Other",])

GPb <- lm(GoProtest ~ MilitarizedPolice, data=svy[svy$race3=="Black",])
GPw <- lm(GoProtest ~ MilitarizedPolice, data=svy[svy$race3=="White",])
GPo <- lm(GoProtest ~ MilitarizedPolice, data=svy[svy$race3=="Other",])

SMb <- lm(SocialMedia ~ MilitarizedPolice, data=svy[svy$race3=="Black",])
SMw <- lm(SocialMedia ~ MilitarizedPolice, data=svy[svy$race3=="White",])
SMo <- lm(SocialMedia ~ MilitarizedPolice, data=svy[svy$race3=="Other",])

stargazer(SPb, SPw, SPo, GIb, GIw, GIo, GPb, GPw, GPo, SMb, SMw, SMo, 
          title="Effect of Heavy Police Presence on Protester Support by Race: Regressions", 
          float.env="sidewaystable",
          type='latex',
          dep.var.caption = "Dependent Variable:",
          column.labels = rep(c("Black","White","Other"),4),
          omit.stat = c("rsq", "f", "ser", "adj.rsq"),
          covariate.labels=c("Heavy Police Presence"),
          star.cutoffs = c(0.05), notes="$^{*}$p$<$0.05", notes.append=FALSE,
          label="SupportbyRaceRegression", style="apsr", column.sep.width = "-5pt",
          out="support_byrace_table.tex")

## Table A10 : Effect of Heavy Police Presence on Violence Perceptions and Protester Support: Black respondents ----

EVi <- lm(EventViolent ~ MilitarizedPolice + black + MilitarizedPolice*black, data=svy)
IVi <- lm(IntentionsViolent ~ MilitarizedPolice + black + MilitarizedPolice*black, data=svy)
CTi <- lm(CauseTrouble ~ MilitarizedPolice + black + MilitarizedPolice*black, data=svy)

SPi <- lm(SupportProtest ~ MilitarizedPolice + black + MilitarizedPolice*black, data=svy)
GIi <- lm(GetInvolved ~ MilitarizedPolice + black + MilitarizedPolice*black, data=svy)
GPi <- lm(GoProtest ~ MilitarizedPolice + black + MilitarizedPolice*black, data=svy)
SMi <- lm(SocialMedia ~ MilitarizedPolice + black + MilitarizedPolice*black, data=svy)

stargazer(EVi, IVi, CTi, SPi, GIi, GPi, SMi, 
          title="Effect of Heavy Police Presence on Violence Perceptions and Protester Support: Black respondents compared to the rest of the sample", 
          float.env="sidewaystable",
          type='latex',
          dep.var.caption = "Dependent Variable:",
          omit.stat = c("rsq", "f", "ser", "adj.rsq"),
          covariate.labels=c("Heavy Police Presence", "Black", "Heavy Police Presence X Black"),
          star.cutoffs = c(0.05), notes="$^{*}$p$<$0.05", notes.append=FALSE,
          label="InteractionbyRaceRegression", style="apsr",
          out="supportandperceptions_byrace_interactiontable.tex")

